package com.example.demo.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.vo.AisShipDaHuaVo;

import java.util.List;

/**
 * @author xumf
 * @date 2020/3/5 8:41
 */
public class ListUtils <T>{

    public static void main(String[] args) throws Exception {
        JSONArray array=new JSONArray();
        JSONObject object=new JSONObject();
        object.put("delayState",11);
        object.put("navigationStatus",null);
        object.put("mmsi",412419088);
        object.put("courseOverGround",26.2);
        object.put("lon",122.16766);
        object.put("lat",28.474792);
        object.put("trueHeadOverGround",511);
        object.put("headDirector",null);
        object.put("time",1582366559189l);

        JSONObject object1=new JSONObject();
        object1.put("delayState",11);
        object1.put("navigationStatus",null);
        object1.put("mmsi",412419288);
        object1.put("courseOverGround",26.2);
        object1.put("lon",122.16766);
        object1.put("lat",28.474792);
        object1.put("trueHeadOverGround",511);
        object1.put("headDirector",null);
        object1.put("time",1582366559189l);
        array.add(object);
        array.add(object1);

        List<AisShipDaHuaVo> list= new ListUtils().ObjectToList(array.toJSONString(),new AisShipDaHuaVo());
        System.out.println(list.toString());
    }

    /**
     * 对象转List
     * @param jsonArr
     * @param t
     * @return
     * @throws Exception
     */
    public  List<T> ObjectToList(String jsonArr,T t) throws Exception{
          Class c = t.getClass();
          List<T> list=JSONObject.parseArray(jsonArr,c);
          return list;
    }
}
